package com.hx.vending.mqtt;

import org.apache.log4j.Logger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class MQTTServletContextListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent servletContextEvent) {
		System.out.println("--------------------------contextInitialized-------------------------------");

		Logger logger = Logger.getLogger(MQTTServletContextListener.class);
		logger.error("监听器执行++++++++");
		//开启连接mqtt线程
		ClientMQTT clientMqttThread = new ClientMQTT();
		Thread t=new Thread(clientMqttThread);

		t.start();

		//分布式锁的测试方法(无用，测试)
		//RedisUtil ru=new RedisUtil();
		//ru.test(5);
	}

	@Override
	public void contextDestroyed(ServletContextEvent servletContextEvent) {
		System.out.println("--------------------------------MQTTServlet.destroy()-------------------------");
	}
}